#include <mysql_driver.h>
#include <mysql_connection.h>
#include <iostream>

int main() {
    try {
        // 创建 MySQL 驱动实例
        sql::mysql::MySQL_Driver *driver = sql::mysql::get_mysql_driver_instance();
        
        if (!driver) {
            std::cerr << "无法获取 MySQL 驱动实例!" << std::endl;
            return 1;
        }
        
        std::cout << "成功获取 MySQL 驱动" << std::endl;
        
        // 建立数据库连接
        sql::Connection *con = driver->connect("tcp://112.74.40.147:3306", "root", "Ahqjhqj73@you");
        
        if (con) {
            std::cout << "成功连接到 MySQL 数据库!" << std::endl;
            
            // 关闭连接
            con->close();
            delete con;
            return 0;
        }
        
        std::cerr << "无法建立连接" << std::endl;
        return 1;
        
    } catch (sql::SQLException &e) {
        std::cerr << "MySQL 错误 #" << e.getErrorCode() << ": " << e.what() << std::endl;
        std::cerr << "SQL 状态: " << e.getSQLState() << std::endl;
        return 1;
    }
}